// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;

namespace SnapObjects.Data.Odbc
{
    internal class OdbcHanaSqlStatementFactory : SqlStatementFactory, IOdbcSqlStatementFactory
    {
        public OdbcHanaSqlStatementFactory(ISqlGenerationHelper helper, ITypeMapper mapper)
            : base(helper, mapper)
        {
        }

        public override ISqlBuilderParser GetBuilderParser(SqlStatementType statementType)
        {
            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    return new OdbcQueryBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.SqlRaw:
                {
                    return new OdbcRawBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Insert:
                {
                    return new OdbcInsertBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Update:
                {
                    return new OdbcUpdateBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Delete:
                {
                    return new OdbcDeleteBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Procedure:
                {
                    return new OdbcProcedureBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Condition:
                {
                    return new OdbcConditionBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Function:
                {
                    return new OdbcFunctionBuilderParser(this, _helper, _mapper);
                }
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }
        }

        public override ISqlStatementGenerator GetSqlGenerator(SqlStatementType statementType)
        {
            ISqlStatementGenerator generator;

            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    generator = new OdbcHanaSqlSelectStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Insert:
                {
                    generator = new OdbcSqlInsertStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Update:
                {
                    generator = new OdbcSqlUpdateStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Delete:
                {
                    generator = new OdbcSqlDeleteStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Procedure:
                {
                    generator = new OdbcSqlProcedureStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Condition:
                {
                    generator = new OdbcSqlConditionStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.SqlRaw:
                {
                    generator = new OdbcSqlRawStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Function:
                {
                    generator = new OdbcHanaSqlFunctionStatementGenerator(this, _helper, _mapper);
                }
                break;
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }

            return generator;
        }

        public override ISqlStatementParser GetSqlParser(SqlStatementType statementType)
        {
            ISqlStatementParser parser;

            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    parser = new OdbcSqlSelectStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Delete:
                {
                    parser = new OdbcSqlDeleteStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Update:
                {
                    parser = new OdbcSqlUpdateStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Insert:
                {
                    parser = new OdbcSqlInsertStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Procedure:
                {
                    parser = new OdbcSqlProcedureStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.SqlRaw:
                {
                    parser = new OdbcSqlRawStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Function:
                {
                    parser = new OdbcSqlFunctionStatementParser(this, _helper);
                }
                break;
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }

            return parser;
        }

        public ISqlTokenizer GetSqlTokenizer(string sqlText, ISqlGenerationHelper helper)
        {
            return new OdbcHanaSqlTokenizer(sqlText, helper);
        }
    }
}
